package 多线程;

import java.util.concurrent.atomic.AtomicIntegerArray;

/**
 * @Author: 朱胜伟
 * @CreateTime: 2021-02-01 14:11
 * @Description:
 */
public class Test02 {
    static AtomicIntegerArray integerArray = new AtomicIntegerArray(10);
    public static void main(String[] args) {
        Thread[] threads = new Thread[10];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new th();
        }
        for (Thread thread : threads) {
            thread.start();
        }
        for (Thread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(integerArray);

    }
    static class th extends Thread{
        @Override
        public void run() {
            for (int i = 0; i< 1000; i++){
                for (int j = 0 ; j < 10; j++){
                    integerArray.incrementAndGet(j);
                }
            }
        }
    }

}
